#include "stdafx.h"
#include "ColorAnimation.hpp"
#include "ITransformable.hpp"

rh::ColorAnimation::ColorAnimation(rh::ITransformable* target, sf::Time animationTime, sf::Color startValue, sf::Color endValue)
	: Animation(target, animationTime, startValue, endValue)
{
	_stepValue = sf::Color();
	_steps[0] = (float(_endValue.r) - float(_startValue.r))/animationTime.asMilliseconds();
	_steps[1] = (float(_endValue.g) - float(_startValue.g))/animationTime.asMilliseconds();
	_steps[2] = (float(_endValue.b) - float(_startValue.b))/animationTime.asMilliseconds();
	_steps[3] = (float(_endValue.a) - float(_startValue.a))/animationTime.asMilliseconds();

}


rh::ColorAnimation::~ColorAnimation(void)
{
}
void rh::ColorAnimation::Start(void)
{

	rh::Animation<sf::Color>::Start();
}

void rh::ColorAnimation::Animate(const sf::Time& elapsedTime)
{
	sf::Color tempStep = sf::Color(
		_startValue.r +	_steps[0] * _animationElapsedTime.asMilliseconds(),
		_startValue.g +	_steps[1] * _animationElapsedTime.asMilliseconds(),
		_startValue.b +	_steps[2] * _animationElapsedTime.asMilliseconds(),
		_startValue.a +	_steps[3] * _animationElapsedTime.asMilliseconds()
		);
	(*_target).setColor(tempStep);
}

void rh::ColorAnimation::CleanupAnimation(void)
{
	(*_target).setColor(_endValue);
}